package cf.huzpsb.bcgod;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

import java.util.Iterator;

public class TpCMD extends Command {
    public TpCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台不能使用此命令");
        } else if (args.length != 1) {
            sender.sendMessage("§c参数错误");
        } else if (((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c登录区域禁止使用!");
        } else {
            Data data = null;
            Iterator var4 = Main.getInstance().getAllData().values().iterator();

            while (var4.hasNext()) {
                Data tmpData = (Data) var4.next();
                if (tmpData.token.equals(args[0])) {
                    data = tmpData;
                    break;
                }
            }

            if (data != null && 180 - (int) (System.currentTimeMillis() / 1000L - data.time) >= 0) {
                ((ProxiedPlayer) sender).connect(Main.getInstance().getProxy().getServerInfo(data.server));
            } else {
                sender.sendMessage(new TextComponent("§c邀请已经过期."));
            }

        }
    }
}
